package com.mofang.powerdekorhelper.activity.mine;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.ExpandableListView;

import com.mofang.powerdekorhelper.R;
import com.mofang.powerdekorhelper.adapter.MyExpandableListAdapter;
import com.mofang.powerdekorhelper.base.MvpActivity;
import com.mofang.powerdekorhelper.model.JHelpAndFeedback;
import com.mofang.powerdekorhelper.persenter.HelpAndFeedBackPerenster;
import com.mofang.powerdekorhelper.utils.LoadPrograss;
import com.mofang.powerdekorhelper.utils.T;
import com.mofang.powerdekorhelper.view.HelpAndFeedBackView;
import com.mofang.powerdekorhelper.witget.TitleBar;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by luofei on 2016/9/5 0005.
 */

public class HelpAndFeedBackActivity extends MvpActivity<HelpAndFeedBackView, HelpAndFeedBackPerenster> implements HelpAndFeedBackView {

    @BindView(R.id.help_and_feedback_title)
    TitleBar mTitleBar;

    // 帮助与反馈
    @BindView(R.id.help_and_feedback_list)
    ExpandableListView expandableListView;

    @BindView(R.id.help_and_feedback_btn)
    Button feedBackBtn;

    private LoadPrograss loadPrograss;

    private MyExpandableListAdapter adapter;

    @Override
    public HelpAndFeedBackPerenster initPresenter() {
        return new HelpAndFeedBackPerenster();
    }

    @Override
    public void initView() {
        inflateLayout(R.layout.activity_help_and_feedback_layout);
        initTitleBarWithback(mTitleBar, R.string.help_and_feedback);
        loadPrograss = new LoadPrograss(this);
    }

    @Override
    public void initData() {

        presenter.getJHelpAndFeedback();
    }

    @OnClick({R.id.help_and_feedback_btn})
    void Onclick(View view) {
        switch (view.getId()) {

            case R.id.help_and_feedback_btn:
                toActivity(this, FeedBackActivity.class);
                break;
        }
    }

    @Override
    public void setHelpAndFeedBackInfo(JHelpAndFeedback helpAndFeedback) {
        if (helpAndFeedback != null) {
            adapter = new MyExpandableListAdapter(this, helpAndFeedback.getResult());
            expandableListView.setAdapter(adapter);

            expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
                @Override
                public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i1, long l) {
                    JHelpAndFeedback.HelpAndFeedbackResult.HelpAndFeedback helpAndFeedback = (JHelpAndFeedback.HelpAndFeedbackResult.HelpAndFeedback) view.getTag();
                    if (helpAndFeedback != null) {
                        startActivity(new Intent(HelpAndFeedBackActivity.this, HelpAndFeedBackDetialesActivity.class).putExtra("HelpDetialesId", helpAndFeedback.getId()));
                    }
                    return false;
                }
            });
        }
    }

    @Override
    public void showProgress() {
        loadPrograss.show();
    }

    @Override
    public void hideProgress() {
        loadPrograss.hide();
    }

    @Override
    public void toast(CharSequence s) {

        T.showShort(this, s);
    }

    @Override
    public void toast(int id) {

    }

    @Override
    public void showNullLayout() {

    }

    @Override
    public void hideNullLayout() {

    }

    @Override
    public void showErrorLayout(View.OnClickListener listener) {

    }

    @Override
    public void hideErrorLayout() {

    }

    @Override
    public void onError(String errorInfo) {

        toast(errorInfo);
    }

}
